<template>
<div class="after-sale-reason views-container">
  <!-- <el-dialog @close="saveDialogForm" :visible.sync="dialogTableVisible" custom-class="reset-pwd wlm-form-dialog dialog-table">
    <div class="wlm-form" v-if="dialogTableVisible">
      <div class="wlm-form-header wlm-dialog-fixheader">
        <span class="wlm-dialog-inlenr">添加轮播图</span>
      </div>
      <el-scrollbar wrap-class="scrollbar-wrapper">
        <div class="wlm-form-content">
          <div class="wlm-dialog-main">
            <div class="wlm-dialog-content">
              <el-form :ref="formFormatData.key" :model="formFormatData.formData" size="small" label-width="120px" class="retail-form" label-position="right" :rules="formFormatData.rules">
                <el-form-item label="轮播排序" prop="sort">
                  <el-input v-model.trim="formFormatData.formData.sort">
                  </el-input>
                  <span>注：数值越大越靠前</span>
                </el-form-item>
                <el-form-item label="轮播图标题" prop="title">
                 <el-input v-model.trim="formFormatData.formData.title">
                  </el-input>
                </el-form-item>
                <el-form-item label="选择链接" prop="link">
                   <el-input v-model.trim="formFormatData.formData.link">
                  </el-input>
                </el-form-item>
                <el-form-item label="添加图片" prop="image">
                   <choose-files ref="chooseFiles" :config="chooseVideostyletConfig" :changeEvt="formFormatFiltersChange"></choose-files>
                    <div class="form-help">次轮播图建议尺寸640*320</div>
                </el-form-item>
                <el-form-item label="是否启用">
                     <el-switch :active-value="1" :inactive-value="2" v-model="formFormatData.formData.is_status"> </el-switch>
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>
      </el-scrollbar>
    </div>
    <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
      <el-button size="small" @click="formFormatSubmit" type="primary">保存</el-button>
    </footer>
  </el-dialog> -->
  <div class="wlm-table">
    <div class="wlm-table-hearder-btn">
      <!-- <el-button size="small" type="primary" @click="showdialog(1)">添加轮播图</el-button> -->
       <router-link class="wlm-text" tag="span" :to="{path:'/merchant/goodshopcarouselAdd'}">
          <el-button size="small" type="primary">添加轮播图</el-button>
        </router-link>
    </div>
    <div class="wlm-table-content">
      <el-table :ref="tableFormatData.goodshop.key" :data="tableFormatData.goodshop.tableData" @selection-change="handleSelectionChange" style="width: 100%">
        <el-table-column prop="date" label="排序" >
          <template slot-scope="scope">
            <span> {{scope.row.sort}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="幻灯片标题" >
          <template slot-scope="scope">
            <span> {{scope.row.title}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="轮播图片" >
          <template slot-scope="scope">
            <!-- v-if="scope.row.goods&&scope.row.goods.image"  -->

          <img height="50" width="50" v-if="scope.row.image.length>0" :src="scope.row.image[0].file_path ">
          </template>
        </el-table-column>
        <el-table-column prop="name" label="链接" >
          <template slot-scope="scope">
           <span> {{scope.row.link}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="是否启用" >
          <template slot-scope="scope">
            <el-switch :active-value="1" :inactive-value="2" @change="changeTableItem({rotation_id:scope.row.rotation_id,is_status:scope.row.is_status},formFormatData.api.change.is_status)"  v-model="scope.row.is_status"> </el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作" >
          <template slot-scope="scope">
            <div class="operation-group">

              <!-- <el-button class="wlm-text" type="text" @click="showdialog(2,scope.row.rotation_id)">编辑</el-button> -->
               <router-link class="wlm-text" tag="a" target="_blank" :to="{path:'/merchant/goodshopcarouselAdd', query :{ 
                 rotation_id:scope.row.rotation_id,
                 store_user_id:$route.query.store_user_id?$route.query.store_user_id:'',
                  h_aid:$route.query.h_aid?$route.query.h_aid:'',}}">
                  <el-button type="text">编辑</el-button>
              </router-link>
              <div class="btn-line"></div>
              <el-button class="wlm-text" type="text"  @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-content flex-row flex-justify-e flex-align-c">
        <!-- <el-row class="pagination-btns">
          <el-checkbox class="check-all"  true-label="1" false-label="0" v-model="tableFormatData.goodshop.files.checkall" @change="toggleSelection">全部</el-checkbox>
          <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
        </el-row> -->
        <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.goodshop.pagination.page" :page-sizes="tableFormatData.goodshop.pagination.pagesizes" :page-size.sync="tableFormatData.goodshop.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.goodshop.pagination.total : 0">
        </el-pagination>
      </div>
    </div>
  </div>
</div>
</template>

<script>
import {
  delGoodShop,
  getdetail,
  goodShopList,
  addGoodShop,
  setStatus
} from '@/api/platform'
import mixins from '@/mixins/mixins'
import ChooseFiles from '@/components/ChooseFiles/index'
export default {
  mixins: [mixins.getters('Table'), mixins.getters('Form')],
  name: 'UserPlatform',
  components: {
    ChooseFiles
  },
  created() {
  },
  data() {
    return {
      dialogTableVisible: false,
      selecUseData: [],
      chooseVideostyletConfig: {
        type: ['image'],
        model: 'display',
        uploadConfig: {
          limit: 1,
          isLocal: true,
          model: 'display'
        },
        initList: [],
        isShowList: true,
        file_type: 'image',
        bindKey: {
          key: 'image',
          model: 'img'
        }
      },
      formFormatData: {
        key: 'goodshop',
        model: {
          noCreateEdit: false,
          bindDialog: 'dialogTableVisible'
        },
        api: {
          editForm: {
            api: getdetail, // 编辑获取表单信息
            params: {
              id: ''
            },
            filters: {
              img: {
                bindInit: ['chooseVideostyletConfig']
              }
            },
            redirect: 'rotation_id'
          },
          submitForm: addGoodShop, // 编辑提交，新增提交
          change: {// 局部修改
            is_status: {
              key: 'is_status',
              api: setStatus
            }
          }
        },
        formData: {
          title: '',
          sort: '',
          is_status: 1,
          image: [],
          link: ''
        },
        rules: {
          sort: [{
            required: true,
            message: '请输入轮播排序',
            trigger: 'blur'
          }],
          title: [{
            required: true,
            message: '请输入标题',
            trigger: 'blur'
          }],
          link: [{
            required: true,
            message: '请填写链接',
            trigger: 'blur'
          }],
          image: [{
            required: true,
            message: '请选择图片',
            trigger: 'blur'
          }]
        }
      },
      tableFormatData: {
        current: 'goodshop',
        goodshop: {
          key: 'goodshop',
          api: {
            getList: goodShopList, // 列表接口
            delList: delGoodShop// 删除接口
          },
          tableData: [],
          files: {
            content: '',
            ids: [],
            checkall: '0',
            Recycle: '1',
            redirect: 'rotation_id'
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
    changeTableCallBack(params) {

    },
    uploadPlatformChange(imgs) {

    },
    saveDialogForm() {
      this.resetDialogFormData({ title: '', sort: '', is_status: 1, image: [], link: '' })
    },
    handleDelete(index, row) { // 删除
      console.log(index, row)
      this.$confirm('此操作将删除此行数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // this.$message({
        //   type: 'success',
        //   message: '删除成功!'
        // });
        delGoodShop({ rotation_id: row.rotation_id }).then(res => {
          const { code } = res.data
          code == 1 && this.$message.success('操作成功')
          this.$router.go(0)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.after-sale-reason {
}
</style>
